package com.atguigu.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @auther zzyy
 * @create 2020-02-19 16:24
 */
//负载均衡减少服务器的访问压力
@RestController
@Slf4j
public class OrderConsulController {

    public static final String INVOKE_URL = "http://consul-provider-payment-8002";
    public static final String INVOKE_URL1 = "http://consul-provider-payment";

    @Resource
    private RestTemplate restTemplate;

    @GetMapping(value = "/consumer/payment/consul")
    public String paymentInfo() {
        String result = restTemplate.getForObject(INVOKE_URL+"/payment/consul",String.class);
        return result;
    }

    @GetMapping("/tian")
    public String list(){
        String result = restTemplate.getForObject(INVOKE_URL+"/payment/consul",String.class);
        return result;
    }

    //判断闰年
    public static boolean leap(int year){
        if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)){
            return true;
        }else {
            return false;
        }
    }

    /**
     * 程序输入一个整数x，以及另一个正整数n，中间用空格分隔，
     * 计算从x年开始后的第n个闰年是哪一年（x的范围为1800至2100；
     * 如果x本身是闰年，则x之后的第一个闰年是x）
     * @param year
     * @param n
     */
    public static void print(int year,int n){
        if(leap(year)){
            if (n == 1){
                System.out.println(year);
            }else {
                int sum = 0;
                for (int i = 1; ; i++) {
                    if(leap(year + 4*i)){
                        sum++;
                    }
                    if(sum == n-1){
                        System.out.println(year + 4*i);
                        break;
                    }
                }
            }
        }else {
            year = year + 4*(n+1);
            for (int i = 1; i < 4; i++) {
                if(leap(year-i)){
                    System.out.println(year - i);
                }
            }
        }
    }

    public static int jump(int n){
        if(n == 1){
            return 1;
        }
        if(n == 2){
            return 2;
        }
        return jump(n - 1) + jump(n - 2);
    }

    public static void main(String[] args) {
        print(2002,3);
        System.out.println(jump(3));
    }
}
